const mongoose=require("mongoose");
mongoose.connect("mongodb://localhost/test");
mongoose.Promise=Promise;
const Schema=mongoose.Schema({
  name:String
});

    var User=mongoose.model("User",Schema);
      var u1=new User({
            name:"kaka"
          });


    async function run(){
           await User.remove();
           await u1.save();
              await User.findByIdAndUpdate(u1.id,{name:"yasuo"});
              //{name:'yasuo',_id:}
               const u2=await User.findById(u1.id);
              await User.findByIdAndRemove(u1.id);
              //null，数据库中的对象被删除
              console.log(await User.findById(u1.id));
              //{name:'kaka',_id:},{name:'yasuo',_id:}
              console.log(u1,u2);
              //因为u2是保存在Javascript环境中的变量，不会受到数据库的影响);
        }
    run();
